﻿//https://leetcode.cn/problems/palindrome-linked-list/?envType=study-plan-v2&envId=top-100-liked

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
    ListNode* dest;
public:
    bool checkPalindrome(ListNode* cur)
    {
        if (cur != nullptr)
        {
            if (!checkPalindrome(cur->next))
            {
                return false;
            }
            if (cur->val != dest->val)
            {
                return false;
            }

            dest = dest->next;
        }

        return true;
    }
    bool isPalindrome(ListNode* head)
    {
        dest = head;
        return checkPalindrome(head);
    }
};